package com.zs.grain.device

import android.content.Context
import com.zslibrary.BusMaster.BusMicroControlUnit
import com.zslibrary.BusMaster.BusNfc
import com.zslibrary.Structure.CardStruct


class McuDevice(val mContext: Context) {
    lateinit var oldLight:EnumLightStatus
    lateinit var busNfc: BusNfc
    lateinit var mcuBus:BusMicroControlUnit

    init {
        oldLight = EnumLightStatus.NULL
        busNfc = BusNfc.getInstance()
        //mcuBus = BusMicroControlUnit.getInstance()
    }

    fun init(){
        //mcuBus.startMCUBus()
        busNfc?.startNfcBus()
        busNfc?.setOnDetectCard(object : BusNfc.OnDetectCard {
            override fun onDetectCard(cardData: CardStruct?) {
                var cardNumber = cardData?.cardSN?.toString()
                if (cardNumber != null) nfcListener?.onSwipeCard(cardNumber)
            }
        })
    }

    var nfcListener: INfcListener? = null
    fun setNfcListenter(listener: INfcListener) {
        nfcListener = listener;
    }

    fun mcuOpenDoor() {
        //mcuBus.openDoor()
    }

    fun mcuCloseDoor() {
        //mcuBus.closeDoor()
    }

    fun mcuLightControl(type: EnumLightStatus) {
        if (type != oldLight) {
            //mcuBus.controlLed(type.value)
            oldLight = type
        }
    }
}
